home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 4- playing sounds / source / animalpane.java next >
Encoding:
Java Source  |  2000-06-23  |  6.5 KB  |  172 lines

  1. import java.awt.*;
  2. import java.lang.*;
  3.  
  4. import java.io.IOException;
  5. import java.io.FileNotFoundException;
  6.  
  7. import quicktime.app.QTFactory;
  8. import quicktime.app.anim.Compositor;
  9. import quicktime.app.image.GraphicsImporterDrawer; 
  10. import quicktime.app.image.ImagePresenter; 
  11. import quicktime.app.image.ImageUtil;
  12. import quicktime.app.players.MoviePresenter;
  13.  
  14. import quicktime.io.QTFile;
  15. import quicktime.io.OpenMovieFile;
  16.  
  17. import quicktime.qd.QDRect;
  18. import quicktime.qd.QDGraphics;
  19. import quicktime.qd.QDColor; 
  20. import quicktime.qd.QDConstants; 
  21.  
  22. import quicktime.qd.QDDrawer;
  23.  
  24. import quicktime.std.image.Matrix;
  25. import quicktime.std.StdQTConstants;
  26. import quicktime.std.movies.Movie; 
  27. import quicktime.std.image.GraphicsMode;
  28.  
  29. import quicktime.QTSession;
  30. import quicktime.QTException; 
  31.  
  32. /**
  33.  * QTZoo Module 3 - Drawing Text Using QTJ
  34.  *
  35.  * @author Michael Hopkins
  36.  * @author Levi Brown
  37.  * @author Apple Computer, Inc.
  38.  * @version 3.0.1  11/15/1999
  39.  *
  40.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  41.  *    
  42.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  43.  *                ("Apple") in consideration of your agreement to the following terms, and your
  44.  *                use, installation, modification or redistribution of this Apple software
  45.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  46.  *                please do not use, install, modify or redistribute this Apple software.
  47.  *
  48.  *                In consideration of your agreement to abide by the following terms, and subject
  49.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  50.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  51.  *                reproduce, modify and redistribute the Apple Software, with or without
  52.  *                modifications, in source and/or binary forms; provided that if you redistribute
  53.  *                the Apple Software in its entirety and without modifications, you must retain
  54.  *                this notice and the following text and disclaimers in all such redistributions of
  55.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  56.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  57.  *                Apple Software without specific prior written permission from Apple.  Except as
  58.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  59.  *                are granted by Apple herein, including but not limited to any patent rights that
  60.  *                may be infringed by your derivative works or by other works in which the Apple
  61.  *                Software may be incorporated.
  62.  *
  63.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  64.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  65.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  66.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  67.  *                COMBINATION WITH YOUR PRODUCTS.
  68.  *
  69.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  70.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  71.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  72.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  73.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  74.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  75.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  76.  *
  77.  * Revision History
  78.  * ---------------------------------------------------------------------------------
  79.  * 12/02/99 MSH  cleaned up code, added comments
  80.  * 
  81.  */
  82. public class AnimalPane
  83. {
  84.     /**
  85.      *  Public default constructor
  86.      *  Creates the map button, and sets up the listeners
  87.      */
  88.     public AnimalPane()
  89.     {
  90.         QDRect size = new QDRect(Zoo3.WIDTH, Zoo3.HEIGHT);
  91.         try
  92.         {
  93.             QDGraphics gw = new QDGraphics( size );            // create a new graphics object
  94.             compositor = new Compositor( gw, QDColor.white, 30, 1 );
  95.         
  96.             QTFile imageFile = new QTFile( 
  97.                 QTFactory.findAbsolutePath( "data/zebra/ZebraBackground.jpg" ));
  98.             GraphicsImporterDrawer drawer = new GraphicsImporterDrawer( imageFile );
  99.             ImagePresenter presenter = ImagePresenter.fromGraphicsImporterDrawer( drawer );
  100.             presenter.setLocation( 110, 110 );                // set location of movie within compositor
  101.             compositor.addMember( presenter, 3 );            // add image presenter to compositor in 2nd layer
  102.             
  103.             addText( "data/zebra/Zebra.txt", 2, 15, 160, 415, 220 );  
  104.             
  105.             Movie m = makeMovie( new QTFile( 
  106.                 QTFactory.findAbsolutePath( "data/zebra/Zebra.mov" )));
  107.             md = new MoviePresenter( m );                    // create presenter from movie file    
  108.             compositor.addMember( md, 1 );                    // add presenter to compositor
  109.             compositor.getTimer().setRate(1);                // start compositor
  110.             md.setRate(1);                                    // start movie
  111.         }
  112.         catch ( IOException e )                                // catch any errors
  113.         {
  114.             e.printStackTrace();
  115.         }
  116.         catch ( QTException e )
  117.         {
  118.             e.printStackTrace();
  119.         }
  120.     }
  121.  
  122.     public Compositor getCompositor( ) { return compositor; }    // returns the compositor associated with the animal pane
  123.  
  124.  
  125.     /**
  126.      * Reads a text file from the disk and displays it in the compositor
  127.      * @param textPath the relative path where the text is located
  128.      * @param layer, the layer of the compositor to add the text to.
  129.      * @param x the x coordinate location.
  130.      * @param y the y coordinate location.
  131.      * @param width the width of the area to display the text.
  132.      * @param height the height of the area to display the text.
  133.      */
  134.     protected void addText( String textPath, int layer, int x, int y, int width, int height )
  135.     {
  136.         try
  137.         {
  138.             TextPresenter text = new TextPresenter( textPath, new Dimension( width, height ));
  139.             
  140.             ImagePresenter presenter = text.getPresenter();
  141.             Matrix theMatrix = new Matrix();
  142.             theMatrix.translate( (float) x, (float) y );
  143.             presenter.setMatrix( theMatrix );
  144.             compositor.addMember( presenter, layer );
  145.         }
  146.         catch ( QTException e )
  147.         {
  148.             e.printStackTrace();
  149.         }
  150.         catch ( FileNotFoundException e )
  151.         {
  152.             e.printStackTrace();
  153.         }    
  154.     }    // MODULE 3 Addition
  155.         
  156.     /**
  157.      * Opens the movie file and sets it up to be played.
  158.      * @param f a QTFile representing the movie to initialize.
  159.      * @return the movie, ready to play
  160.      */
  161.     protected Movie makeMovie( QTFile f ) throws IOException, QTException
  162.     {
  163.         OpenMovieFile movieFile = OpenMovieFile.asRead(f);
  164.         Movie m = Movie.fromFile( movieFile );
  165.         m.getTimeBase().setFlags( StdQTConstants.loopTimeBase );// we want the movie to loop    
  166.         return m;    
  167.     }
  168.         
  169.     protected Compositor compositor;
  170.     protected MoviePresenter md;
  171. }
  172.